﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Zadatak5.Tests
{
    [TestClass]
    public class StringCalculatorTest
    {
        StringCalculator calc = new StringCalculator();

        [TestMethod]
        public void should_return_0_for_empty_string()
        {
            Assert.AreEqual(0, calc.Add(""));
        }

        [TestMethod]
        public void should_return_integer_of_single_number()
        {
            Assert.AreEqual(1, calc.Add("1"));
            Assert.AreEqual(5, calc.Add("5"));
        }

        [TestMethod]
        public void should_return_sum_of_2_numbers()
        {
            Assert.AreEqual(3, calc.Add("1,2"));
            Assert.AreEqual(5, calc.Add("2,3"));
        }

        [TestMethod]
        public void should_handle_unknown_amount_of_numbers()
        {
            Assert.AreEqual(3, calc.Add("1,1,1"));
            Assert.AreEqual(10, calc.Add("1,2,3,4"));
            Assert.AreEqual(15, calc.Add("1,2,3,4,5"));
            Assert.AreEqual(21, calc.Add("1,2,3,4,5,6"));
        }

        [TestMethod]
        public void should_handle_newline_separator_instead_of_comma()
        {
            Assert.AreEqual(10, calc.Add("1\n2,3\n4"));
            Assert.AreEqual(6, calc.Add("1,2\n3"));
            Assert.AreEqual(3, calc.Add("1\n2"));
        }

        [TestMethod]
        public void should_support_different_delimiters()
        {
            Assert.AreEqual(3, calc.Add("//;\n1;2"));
            Assert.AreEqual(6, calc.Add("//;\n1;2;3"));
            Assert.AreEqual(10, calc.Add("//;\n1\n2;3,4"));
        }

        [TestMethod]
        public void should_throw_if_adding_negatives()
        {
            try
            {
                calc.Add("-1,2,-3");
                Assert.Fail();
            } catch (ArgumentException expected)
            {
                Assert.AreEqual("negatives not allowed: -1,-3", expected.Message);
            }
        }
    }
}
